package com.star.star.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.star.star.Activity.AidDetailsActivity;
import com.star.star.R;
import com.star.star.bean.aidBean;

import java.util.List;

public class LeftAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<aidBean> daBeans;

    public LeftAdapter(Context context, List<aidBean> daBeans) {
        this.context = context;
        this.daBeans = daBeans;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_item, parent, false);
        return new MYholder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MYholder mYholder = (MYholder) holder;
        mYholder.setdata(position);
        mYholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AidDetailsActivity.class);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return daBeans.size();
    }

    private class MYholder extends RecyclerView.ViewHolder {

        private final ImageView imageView;
        private final TextView tv_title,tv_time,tv_ping_num,tv_yue_num;

        public MYholder(View view) {
            super(view);
            imageView = view.findViewById(R.id.iv_image);
            tv_title = view.findViewById(R.id.tv_title);
            tv_time = view.findViewById(R.id.tv_time);
            tv_ping_num = view.findViewById(R.id.tv_ping_num);
            tv_yue_num = view.findViewById(R.id.tv_yue_num);
        }

        public void setdata(int position) {
            Glide.with(context).load(daBeans.get(position).getImage()).placeholder(R.mipmap.no_hand).error(R.mipmap.no_hand).into(imageView);
            tv_title.setText(daBeans.get(position).getTitile());
            tv_time.setText(daBeans.get(position).getTime());
            tv_ping_num.setText("评 "+daBeans.get(position).getReadNum());
            tv_yue_num.setText("阅 "+daBeans.get(position).getComments());
         }
    }
}
